﻿using System;
using Community.CsharpSqlite.Entity;
namespace Community.CsharpSqlite
{
    public static class Const
    {
        #region bitvec_c

        /* Size of the Bitvec structure in bytes. */
        public static int BITVEC_SZ = IntPtr.Size*128; //(sizeof(void*)*128)  /* 512 on 32bit.  1024 on 64bit */


        /* Round the union size down to the nearest pointer boundary, since that's how
        ** it will be aligned within the Bitvec struct. */
        //#define BITVEC_USIZE     (((BITVEC_SZ-(3*sizeof(uint)))/sizeof(Bitvec*))*sizeof(Bitvec*))
        public static int BITVEC_USIZE = (((BITVEC_SZ - (3*sizeof (uint)))/4)*4);

        /* Type of the array "element" for the bitmap representation.
        ** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
        ** Setting this to the "natural word" size of your CPU may improve
        ** performance. */
        //#define BITVEC_TELEM     byte
        //using BITVEC_TELEM     = System.Byte;

        /* Size, in bits, of the bitmap element. */
        //#define BITVEC_SZELEM    8
        public const int BITVEC_SZELEM = 8;

        /* Number of elements in a bitmap array. */
        //#define BITVEC_NELEM     (BITVEC_USIZE/sizeof(BITVEC_TELEM))
        public static int BITVEC_NELEM = (BITVEC_USIZE/sizeof (byte));

        /* Number of bits in the bitmap array. */
        //#define BITVEC_NBIT      (BITVEC_NELEM*BITVEC_SZELEM)
        public static int BITVEC_NBIT = (BITVEC_NELEM*BITVEC_SZELEM);

        /* Number of uint values in hash table. */
        //#define BITVEC_NINT      (BITVEC_USIZE/sizeof(uint))
        public static uint BITVEC_NINT = (uint) (BITVEC_USIZE/sizeof (uint));

        /* Maximum number of entries in hash table before
        ** sub-dividing and re-hashing. */
        //#define BITVEC_MXHASH    (BITVEC_NINT/2)
        public static int BITVEC_MXHASH = (int) (BITVEC_NINT/2);

        /* Hashing function for the aHash representation.
        ** Empirical testing showed that the *37 multiplier
        ** (an arbitrary prime)in the hash function provided
        ** no fewer collisions than the no-op *1. */
        //#define BITVEC_HASH(X)   (((X)*1)%BITVEC_NINT)
        public static uint BITVEC_HASH(uint X)
        {
            return (((X)*1)%BITVEC_NINT);
        }

        public static int BITVEC_NPTR = (BITVEC_USIZE/4); //sizeof(Bitvec *));

        #endregion

        #region sqliteInt_h

        /*
    ** If compiling for a processor that lacks floating point support,
    ** substitute integer for floating-point
    */
#if SQLITE_OMIT_FLOATING_POINT
//# define double long
//# define LONGDOUBLE_TYPE long
//#if !SQLITE_BIG_DBL
//#   define SQLITE_BIG_DBL (((long)1)<<50)
//# endif
//# define SQLITE_OMIT_DATETIME_FUNCS 1
//# define SQLITE_OMIT_TRACE 1
//# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
//# undef SQLITE_HAVE_ISNAN
#endif
#if !SQLITE_BIG_DBL
        public const double SQLITE_BIG_DBL = (((long)1) << 60); //# define SQLITE_BIG_DBL (1e99)
#endif


        /*
** The "file format" number is an integer that is incremented whenever
** the VDBE-level file format changes.  The following macros define the
** the default file format for new databases and the maximum file format
** that the library can read.
*/
        public static int SQLITE_MAX_FILE_FORMAT = 4; //#define SQLITE_MAX_FILE_FORMAT 4
        //#if !SQLITE_DEFAULT_FILE_FORMAT
        public static int SQLITE_DEFAULT_FILE_FORMAT = 1; //# define SQLITE_DEFAULT_FILE_FORMAT 1
        //#endif

        /*
    ** Name of the master database table.  The master database table
    ** is a special table that holds the names and attributes of all
    ** user tables and indices.
    */
        public const string MASTER_NAME = "sqlite_master"; //#define MASTER_NAME       "sqlite_master"
        public const string TEMP_MASTER_NAME = "sqlite_temp_master"; //#define TEMP_MASTER_NAME  "sqlite_temp_master"




        /*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
** afterward. Having this macro allows us to cause the C compiler
** to omit code used by TEMP tables without messy #if !statements.
*/
#if SQLITE_OMIT_TEMPDB
//#define OMIT_TEMPDB 1
#else
        public static int OMIT_TEMPDB;
#endif


        /*
    ** The root-page of the master database table.
    */
        public const int MASTER_ROOT = 1; //#define MASTER_ROOT       1

        /*
    ** A sort order can be either ASC or DESC.
    */
        public const int SQLITE_SO_ASC = 0; //#define SQLITE_SO_ASC       0  /* Sort in ascending order */
        public const int SQLITE_SO_DESC = 1; //#define SQLITE_SO_DESC     1  /* Sort in ascending order */


        /*
    ** Additional bit values that can be ORed with an affinity without
    ** changing the affinity.
    */

        public const int SQLITE_JUMPIFNULL = 0x08;
        //#define SQLITE_JUMPIFNULL   0x08  /* jumps if either operand is NULL */

        public const int SQLITE_STOREP2 = 0x10;
        //#define SQLITE_STOREP2      0x10  /* Store result in reg[P2] rather than jump */

        public const int SQLITE_NULLEQ = 0x80; //#define SQLITE_NULLEQ       0x80  /* NULL=NULL */



        public const int IN_INDEX_ROWID = 1; //#define IN_INDEX_ROWID           1
        public const int IN_INDEX_EPH = 2; //#define IN_INDEX_EPH             2
        public const int IN_INDEX_INDEX = 3; //#define IN_INDEX_INDEX           3
        //int ExprHelper.FindInIndex(Parse *, Expr *, int*);

        /*
    ** Flags passed to the ExprHelper.ExprDup() function. See the header comment
    ** above ExprHelper.ExprDup() for details.
    */
        //#define EXPRDUP_REDUCE         0x0001  /* Used reduced-size Expr nodes */
        public const int EXPRDUP_REDUCE = 0x0001;

        /*
    ** Macros to determine the number of bytes required by a normal Expr
    ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
    ** and an Expr struct with the EP_TokenOnly flag set.
    */
        //#define EXPR_FULLSIZE           sizeof(Expr)           /* Full size */
        //#define EXPR_REDUCEDSIZE        offsetof(Expr,iTable)  /* Common features */
        //#define EXPR_TOKENONLYSIZE      offsetof(Expr,pLeft)   /* Fewer features */

        // We don't use these in C#, but define them anyway,
        public const int EXPR_FULLSIZE = 48;
        public const int EXPR_REDUCEDSIZE = 24;
        public const int EXPR_TOKENONLYSIZE = 8;


        /*
    ** The following are the meanings of bits in the Expr.flags2 field.
    */
        //#define EP2_MallocedToken  0x0001  /* Need to MemPool.DbFree() Expr.zToken */
        //#define EP2_Irreducible    0x0002  /* Cannot EXPRDUP_REDUCE this Expr */
        public const byte EP2_MallocedToken = 0x0001;
        public const byte EP2_Irreducible = 0x0002;


#if SQLITE_OMIT_VIRTUALTABLE
        public static bool IN_DECLARE_VTAB; //#define IN_DECLARE_VTAB 0
#else
//  int ;//#define IN_DECLARE_VTAB (pParse.declareVtab)
#endif



        /*
    ** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
    ** Older versions of SQLite used an optional THREADSAFE macro.
    ** We support that for legacy
    */
#if !SQLITE_THREADSAFE
#if THREADSAFE
//# define SQLITE_THREADSAFE THREADSAFE
#else
        //# define SQLITE_THREADSAFE 1
        public const int SQLITE_THREADSAFE = 1;
#endif
#else
const int SQLITE_THREADSAFE = 1;
#endif


        /*
** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
** It determines whether or not the features related to
** ConfigOption.SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
** be overridden at runtime using the ConfigHelper.Sqlite3Config() API.
*/
#if !(SQLITE_DEFAULT_MEMSTATUS)
        //# define SQLITE_DEFAULT_MEMSTATUS 1
        public const int SQLITE_DEFAULT_MEMSTATUS = 0;
#else
const int SQLITE_DEFAULT_MEMSTATUS = 1;
#endif


        /*
    ** SQLITE_MAX_U32 is a ulong constant that is the maximum ulong value
    ** that can be stored in a uint without loss of data.  The value
    ** is 0x00000000ffffffff.  But because of quirks of some compilers, we
    ** have to specify the value in the less intuitive manner shown:
    */
        //#define SQLITE_MAX_U32  ((((ulong)1)<<32)-1)
        public const uint SQLITE_MAX_U32 = (uint)((((ulong)1) << 32) - 1);

        /*
    ** The following value as a destructor means to use MemPool.DbFree().
    ** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT.
    */
        //#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)MemPool.DbFree)
        public static dxDel SQLITE_DYNAMIC;

        /*
** Constants for the largest and smallest possible 64-bit signed integers.
** These macros are designed to work correctly on both 32-bit and 64-bit
** compilers.
*/
        //#define LARGEST_INT64  (0xffffffff|(((long)0x7fffffff)<<32))
        //#define SMALLEST_INT64 (((long)-1) - LARGEST_INT64)
        public const long LARGEST_INT64 = long.MaxValue; //( 0xffffffff | ( ( (long)0x7fffffff ) << 32 ) );
        public const long SMALLEST_INT64 = long.MinValue; //( ( ( long ) - 1 ) - LARGEST_INT64 );

        /*
   ** Possible values for the sqlite.magic field.
   ** The numbers are obtained at random and have no special meaning, other
   ** than being distinct from one another.
   */

        public const int SQLITE_MAGIC_OPEN = 0x1029a697;
        //#define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */

        public const int SQLITE_MAGIC_CLOSED = 0x2f3c2d33;
        //#define SQLITE_MAGIC_CLOSED   0x9f3c2d33  /* Database is closed */

        public const int SQLITE_MAGIC_SICK = 0x3b771290;
        //#define SQLITE_MAGIC_SICK     0x4b771290  /* Error and awaiting close */

        public const int SQLITE_MAGIC_BUSY = 0x403b7906;
        //#define SQLITE_MAGIC_BUSY     0xf03b7906  /* Database currently in use */

        public const int SQLITE_MAGIC_ERROR = 0x55357930;
        //#define SQLITE_MAGIC_ERROR    0xb5357930  /* An StatusCode.SQLITE_MISUSE error occurred */


        /*
    ** Size of the column cache
    */
#if !SQLITE_N_COLCACHE
        //# define SQLITE_N_COLCACHE 10
        public const int SQLITE_N_COLCACHE = 10;
#endif

        /*
    ** The bitmask datatype defined below is used for various optimizations.
    **
    ** Changing this from a 64-bit to a 32-bit type limits the number of
    ** tables in a join to 32 instead of 64.  But it also reduces the size
    ** of the library by 738 bytes on ix86.
    */
        //typedef ulong ulong;

        /*
        ** The number of bits in a ulong.  "BMS" means "BitMask Size".
        */
        //#define BMS  ((int)(sizeof(ulong)*8))
        public const int BMS = ((sizeof (ulong)*8));

  


      
        /*
       ** The number of different kinds of things that can be limited
       ** using the sqlite3_limit() interface.
       */
        //#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1)
        public const int SQLITE_N_LIMIT = LimitCategory.SQLITE_LIMIT_TRIGGER_DEPTH + 1;

        #endregion

        #region BtreeInt_h

        /*
    ** Maximum depth of an SQLite B-Tree structure. Any B-Tree deeper than
    ** this will be declared corrupt. This value is calculated based on a
    ** maximum database size of 2^31 pages a minimum fanout of 2 for a
    ** root-node and 3 for all other internal nodes.
    **
    ** If a tree that appears to be taller than this is encountered, it is
    ** assumed that the database is corrupt.
    */
        //#define BTCURSOR_MAX_DEPTH 20
        public const int BTCURSOR_MAX_DEPTH = 20;

        #endregion

        #region memjournal_c

        /* Space to hold the rollback journal is allocated in increments of
    ** this many bytes.
    **
    ** The size chosen is a little less than a power of two.  That way,
    ** the FileChunk object will have a size that almost exactly fills
    ** a power-of-two allocation.  This mimimizes wasted space in power-of-two
    ** memory allocators.
    */
        //#define JOURNAL_CHUNKSIZE ((int)(1024-sizeof(FileChunk*)))
        public const int JOURNAL_CHUNKSIZE = 4096;

        #endregion


        #region vdbeInt_h
        /*
    ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
    */
        public const int CACHE_STALE = 0;

        #endregion

        #region sqlite3_h


        /*
    ** CAPI3REF: Status Parameters for database connections
    ** EXPERIMENTAL
    **
    ** These constants are the available integer "verbs" that can be passed as
    ** the second argument to the [sqlite3_db_status()] interface.
    **
    ** New verbs may be added in future releases of SQLite. Existing verbs
    ** might be discontinued. Applications should check the return code from
    ** [sqlite3_db_status()] to make sure that the call worked.
    ** The [sqlite3_db_status()] interface will return a non-zero error code
    ** if a discontinued or unsupported verb is invoked.
    **
    ** <dl>
    ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
    ** <dd>This parameter returns the number of lookaside memory slots currently
    ** checked out.</dd>)^
    ** </dl>
    */
        //#define SQLITE_DBSTATUS_LOOKASIDE_USED     0
        public const int SQLITE_DBSTATUS_LOOKASIDE_USED = 0;


        /*
    ** CAPI3REF: Constants Defining Special Destructor Behavior
    **
    ** These are special values for the destructor that is passed in as the
    ** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
    ** argument is SQLITE_STATIC, it means that the content pointer is constant
    ** and will never change.  It does not need to be destroyed.  ^The
    ** SQLITE_TRANSIENT value means that the content will Utility.Likely change in
    ** the near future and that SQLite should make its own private copy of
    ** the content before returning.
    **
    ** The typedef is necessary to work around problems in certain
    ** C++ compilers.  See ticket #2191.
    */
        //typedef void (*sqlite3_destructor_type)(void*);
        //#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
        //#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
        public static dxDel SQLITE_STATIC;
        public static dxDel SQLITE_TRANSIENT;


     


      

      
        /*
   ** CAPI3REF: Text Encodings
   **
   ** These constant define integer codes that represent the various
   ** text encodings supported by SQLite.
   */
        //#define SQLITE_UTF8           1
        //#define SQLITE_UTF16LE        2
        //#define SQLITE_UTF16BE        3
        //#define SQLITE_UTF16          4    /* Use native byte order */
        //#define SQLITE_ANY            5    /* sqlite3_create_function only */
        //#define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */

        public const byte SQLITE_UTF16LE = 2;
        public const byte SQLITE_UTF16BE = 3;
        public const byte SQLITE_UTF16 = 4;
        public const byte SQLITE_ANY = 5;
        public const byte SQLITE_UTF16_ALIGNED = 8;
        public const byte SQLITE_UTF8 = 1;
        #endregion

        #region rowset_c

        /*
    ** The number of rowset entries per allocation chunk.
    */
        //#define ROWSET_ENTRY_PER_CHUNK  \
        //                     ((ROWSET_ALLOCATION_SIZE-8)/sizeof(struct RowSetEntry))
        public const int ROWSET_ENTRY_PER_CHUNK = 63;

        #endregion

        #region sqliteLimit_h

        /*
** The maximum number of in-memory pages to use for the main database
** table and for temporary tables.  The SQLITE_DEFAULT_CACHE_SIZE
*/
#if !SQLITE_DEFAULT_CACHE_SIZE
        public const int SQLITE_DEFAULT_CACHE_SIZE = 2000;
#endif
#if !SQLITE_DEFAULT_TEMP_CACHE_SIZE
        public const int SQLITE_DEFAULT_TEMP_CACHE_SIZE = 500;
#endif



        /*
** The default size of a database page.
*/
#if !SQLITE_DEFAULT_PAGE_SIZE
        public const int SQLITE_DEFAULT_PAGE_SIZE = 1024;
#endif
#if SQLITE_DEFAULT_PAGE_SIZE //SQLITE_DEFAULT_PAGE_SIZE>SqliteLimit.SQLITE_MAX_PAGE_SIZE
//# undef SQLITE_DEFAULT_PAGE_SIZE
const int SQLITE_DEFAULT_PAGE_SIZE SqliteLimit.SQLITE_MAX_PAGE_SIZE
#endif

        /*
** The maximum number of attached databases.  This must be between 0
** and 30.  The upper bound on 30 is because a 32-bit integer bitmap
** is used internally to track attached databases.
*/
#if !SQLITE_MAX_ATTACHED
        public const int SQLITE_MAX_ATTACHED = 10;
#endif

        #endregion

        #region parse_c
#if !YYSTACKDEPTH
        public const int YYSTACKDEPTH = 100;
#endif
        #endregion

        #region Btree_h
        /*
    ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
    ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
    */
#if !SQLITE_DEFAULT_AUTOVACUUM
        public const int SQLITE_DEFAULT_AUTOVACUUM = 0;
#endif
        #endregion

    }
}